

#include "dri_sht20.h"
#include "dri_iic.h"
#include "dri_systick.h"
#include "stdio.h"
sht20_val tem_hum_data;
void dri_sht20_init(void)
{
	dri_iic_init();
}
uint16_t dri_sht20_read(void)
{
	uint8_t data[2];
	uint16_t ret=0;
	dri_iic_start();
	dri_iic_senddata(0x80);
	if(dri_iic_waitACK()!=ACK)
	{
		dri_iic_stop();
		return NoACK;
	}
	dri_iic_senddata(0xE3);
	if(dri_iic_waitACK()!=ACK)
	{
		dri_iic_stop();
		return NoACK;
	}
	dri_systick_ms(85);
	dri_iic_start();
	dri_iic_senddata(0x81);
	if(dri_iic_waitACK()!=ACK)
	{
		dri_iic_stop();
		return NoACK;
	}

	data[0]=dri_iic_readdata(ACK);
	data[1]=dri_iic_readdata(NoACK);
	dri_iic_stop();
	printf("data[0]=%d,data[1]=%d\r\n",data[0],data[1]);
	ret=((data[0]<<8) | data[1]);
	return ret;
}
uint8_t dri_sht20_reset(void)
{
	dri_iic_start();
	dri_iic_senddata(0x80);
	if(dri_iic_waitACK()!=ACK)
	{
		dri_iic_stop();
		return NoACK;
	}
	dri_iic_senddata(0xFE);
	if(dri_iic_waitACK()!=ACK)
	{
		dri_iic_stop();
		return NoACK;
	}
	dri_iic_stop();
	dri_systick_ms(15);
	return 0;
}
void dri_sht20_getdata(void)
{
	
	uint16_t  temp=dri_sht20_read();
	tem_hum_data.tem = -46.85+175.72*((float)temp/65536);
	printf("Temperature=%.2f\r\n",tem_hum_data.tem);
}
